import axios from 'axios'
import url from '../url'
import {getToken} from './token'

const http = axios.create({
  baseURL: url
})
// Add a request interceptor
http.interceptors.request.use(function (config) {
  // Do something before request is sent
  // console.log(config);
  if (config.url === 'login' || config.url === 'homes/swipe') {
    return config
  } else {
    const token = getToken()
    config.headers.Authorization = token
    return config
  }
}, function (error) {
  // Do something with request error
  return Promise.reject(error);
});

// Add a response interceptor
http.interceptors.response.use(function (response) {
  // Do something with response data
  return response.data
}, function (error) {
  // Do something with response error
  return Promise.reject(error);
});
export default http
